Skip to content

Add replay-safe logging#295

Open
bachuv wants to merge 1 commit into
mainfrom
vabachu/replay-safe-logger-java
Open

Add replay-safe logging#295
bachuv wants to merge 1 commit into
mainfrom
vabachu/replay-safe-logger-java

Conversation

@bachuv

@bachuv bachuv commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces a new replay-safe logging feature for orchestrations, ensuring that log output is suppressed during replay segments to prevent duplicate log entries. It includes the implementation of a ReplaySafeLogger, integration into the orchestration context, comprehensive documentation, and a new integration test to validate the behavior.

Replay-safe logging feature:

  • Added the ReplaySafeLogger class, which wraps a standard Logger and suppresses log output when the orchestration is replaying. This prevents duplicate logs during state reconstruction. (client/src/main/java/com/microsoft/durabletask/ReplaySafeLogger.java)
  • Introduced the createReplaySafeLogger default method to the TaskOrchestrationContext interface, allowing orchestrator code to easily obtain a replay-safe logger. (client/src/main/java/com/microsoft/durabletask/TaskOrchestrationContext.java)
  • Updated the documentation to explain how to use replay-safe logging, including code examples and guidance for Azure Functions scenarios. (README.md)
  • Added a changelog entry describing the new createReplaySafeLogger API. (CHANGELOG.md)

Testing:

  • Added an integration test to verify that log messages from orchestrators and activities are emitted exactly once, even when orchestrations replay. (client/src/test/java/com/microsoft/durabletask/IntegrationTests.java)

These changes improve the reliability and usability of orchestration logging by preventing duplicate log entries during replay, while providing clear documentation and tests for the new functionality.

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes are added to the CHANGELOG.md
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Additional PR information

Copilot AI review requested due to automatic review settings July 21, 2026 00:12
@bachuv
bachuv requested a review from a team as a code owner July 21, 2026 00:12
}

@Override
public void logrb(
}

@Override
public void logp(
}

@Override
public void log(Level level, String message, Object parameter) {

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a replay-safe orchestration logging capability to the Durable Task Java client by providing a Logger wrapper that suppresses log emissions during orchestration replay, reducing duplicated log output.

Changes:

  • Introduces ReplaySafeLogger and a TaskOrchestrationContext#createReplaySafeLogger(Logger) convenience API.
  • Documents replay-safe logging usage patterns (including Azure Functions guidance) in the README and adds a changelog entry.
  • Adds unit and integration tests validating suppression during replay and single emission during live segments.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
samples-azure-functions/src/main/java/com/functions/AzureFunctions.java Updates the Azure Functions sample orchestrator to use createReplaySafeLogger for replay-safe logs.
README.md Adds documentation and examples for replay-safe orchestration logging.
client/src/main/java/com/microsoft/durabletask/TaskOrchestrationContext.java Adds the createReplaySafeLogger(Logger) default method API.
client/src/main/java/com/microsoft/durabletask/ReplaySafeLogger.java Implements the replay-suppressing Logger wrapper.
client/src/test/java/com/microsoft/durabletask/ReplaySafeLoggerTest.java Adds focused unit tests for suppression behavior and delegation semantics.
client/src/test/java/com/microsoft/durabletask/TaskOrchestrationExecutorTest.java Adds an executor-level test validating replay suppression vs live emission.
client/src/test/java/com/microsoft/durabletask/IntegrationTests.java Adds an end-to-end integration test covering parent/child orchestrations and activity logging behavior.
CHANGELOG.md Records the new createReplaySafeLogger API addition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +683 to +698
Logger delegate = Logger.getAnonymousLogger();
delegate.setUseParentHandlers(false);
delegate.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
messages.add(record.getMessage());
}

@Override
public void flush() {
}

@Override
public void close() {
}
});
Comment thread README.md
Logger logger = ctx.createReplaySafeLogger(
Logger.getLogger(MyOrchestration.class.getName()));

logger.info("Starting orchestration " + ctx.getInstanceId());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants